<template>
  <div>
    <el-button type="primary" @click="handleClick">主要按钮</el-button>
  </div>
</template>

<script>
  import presskey from '@utils/presskey.js'
  export default {
    data() {
      return {
        time: 3
      }
    },
    methods: {
      async handleClick() {
        this.time = 3
        setTimeout(() => {
          presskey(27)
        }, 3000)
        // let time = 3
        let timer = setInterval(() => {
          console.log('111')
          this.time--
        }, 1000);
        // todo alert 中的 倒计时
        await this.$alert(`<div>${this.time}</div>`, 'title', {
            // 是否可通过按下 ESC 键关闭 alert
            closeOnPressEscape: true,
            dangerouslyUseHTMLString: true
          })
          .then(() => {
            clearInterval(timer)
            timer = null
          })
          .catch((err) => {
            clearInterval(timer)
            timer = null
            console.log('---', err)
          })
      }
    },
  }
</script>

<style scoped></style>